package com.cn.web.filter;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class MyRequest extends HttpServletRequestWrapper implements HttpServletRequest{
	private Map<String,String[]> map2;
	
	public MyRequest(HttpServletRequest request) {
		super(request);
		Map<String,String[]> map = request.getParameterMap();
		map2 = new HashMap<String,String[]>();
		for(Entry<String,String[]> en:map.entrySet()){
			String key = en.getKey();
			String[] str = en.getValue();
			for(int i=0;i<str.length;i++){
				try {
					str[i] = new String(str[i].getBytes("ISO-8859-1"),"UTF-8");
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			map2.put(key, str);
		}
	}

	@Override
	public String getParameter(String name) {
		String[] str = map2.get(name);
		if(str!=null && str.length>0){
			return str[0];
		}
		return null;
	}

	@Override
	public Map getParameterMap() {
		return map2;
	}

	@Override
	public String[] getParameterValues(String name) {
		return map2.get(name);
	}
}
